package top.xuziyi.crawler.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xuziyi.common.pojo.StockCwzb;
import top.xuziyi.crawler.dao.StockCwzbDao;

import java.util.List;

@Service
public class StockCwzbService {

    @Autowired
    private StockCwzbDao stockCwzbDao;

    /**
     * 如果有就不处理,如果没有就修改
     * @param stockCwzbList
     */
    @Transactional
    public void batchSave(List<StockCwzb> stockCwzbList) {
        for (StockCwzb stockCwzb : stockCwzbList) {
            if (stockCwzbDao.findBySymbolAndDate(stockCwzb.getSymbol(), stockCwzb.getDate()) == 0) {
                stockCwzbDao.save(stockCwzb);
            }
        }

    }

    /**
     * 无论有没有都进行新增或者修改
     * @param stockCwzbList
     */
    @Transactional
    public void batchSave2(List<StockCwzb> stockCwzbList) {
        for (StockCwzb stockCwzb : stockCwzbList) {
            stockCwzbDao.save(stockCwzb);
        }

    }
}
